package com.skd.mall.product.service.impl;

import com.skd.mall.product.dao.SkuInfoDao;
import com.skd.mall.product.entity.SkuInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.skd.common.utils.PageUtils;
import com.skd.common.utils.Query;

import com.skd.mall.product.dao.SpuInfoDescDao;
import com.skd.mall.product.entity.SpuInfoDescEntity;
import com.skd.mall.product.service.SpuInfoDescService;


@Service("spuInfoDescService")
public class SpuInfoDescServiceImpl extends ServiceImpl<SpuInfoDescDao, SpuInfoDescEntity> implements SpuInfoDescService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SpuInfoDescEntity> page = this.page(
                new Query<SpuInfoDescEntity>().getPage(params),
                new QueryWrapper<SpuInfoDescEntity>()
        );

        return new PageUtils(page);
    }

    @Autowired
    private SkuInfoDao skuInfoDao;
    @Override
    public SpuInfoDescEntity getSpuDescBySkuId(Long skuId) {
        SkuInfoEntity skuInfo = skuInfoDao.selectOne(
                new QueryWrapper<SkuInfoEntity>().eq("sku_id", skuId)
        );
        SpuInfoDescEntity desc = this.getOne(
                new QueryWrapper<SpuInfoDescEntity>().eq("spu_id", skuInfo.getSpuId())
        );
        return desc;
    }

}